package Java测试.编码4copycopy;

//4.数组[8,5,6,1,2,3,4,7],使用冒泡循环和选择排序完成从小到大进行排序
public class 选择排序 {
    public static void main(String[] args) {
        int[]arr={8,5,6,1,2,3,4,7};
        for (int i = 0; i <arr.length; i++) {
            int maxindex=0;
            for (int j = 0; j <arr.length-i; j++) {
                if (arr[j]>arr[maxindex]){
                    maxindex=j;
                }
                int x=arr[maxindex];
                arr[maxindex]=arr[arr.length-i-1];
                arr[arr.length-i-1]=x;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
        }
    }
}
